<?php
/*
 * Created on 19.07.2008
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
?>
<script language="JavaScript" type="text/javascript">
function boldSelection(){
	//code for mozilla
	if (typeof(myArea.selectionStart) != "undefined") {
		tag = "br"

		var begin = myArea.value.substr(0, myArea.selectionStart);
		var selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);
		var end = myArea.value.substr(myArea.selectionEnd);
		myArea.value = begin + "<" + tag + ">"  + selection + "</" + tag + ">"  + end;
	}
}

function formatText (tag) {
	tagstart = "<" + tag + ">";
	tagend = "</" + tag + ">";

	//code for Mozilla
	el = document.getElementById('myArea');
	if (el.setSelectionRange) {
 		el.value = el.value.substring(0,el.selectionStart) + tagstart + el.value.substring(el.selectionStart,el.selectionEnd) + tagend + el.value.substring(el.selectionEnd,el.value.length)
  	}
  	else {
  		//code for IE
	    var selectedText = document.selection.createRange().text;

	    if (selectedText != "") {
	        var newText = tagstart + selectedText + tagend;
	        document.selection.createRange().text = newText;

	        //search(newText.value,'myArea');
	    }
  	}


}


function setFontSize (size) {
	tagstart = "<font size='" + size + "'>";
	tagend = "</font>";

	//code for Mozilla
	el = document.getElementById('myArea');
	if (el.setSelectionRange) {
 		el.value = el.value.substring(0,el.selectionStart) + tagstart + el.value.substring(el.selectionStart,el.selectionEnd) + tagend + el.value.substring(el.selectionEnd,el.value.length)
  	}
  	else {
  		//code for IE
	    var selectedText = document.selection.createRange().text;

	    if (selectedText != "") {
	        var newText = tagstart + selectedText + tagend;
	        document.selection.createRange().text = newText;
	    }
  	}
}

function setSelRange(selStart, selEnd) {
	inputEl = document.getElementById('myArea');
 if (inputEl.setSelectionRange) {
  inputEl.focus();
  inputEl.setSelectionRange(selStart, selEnd);
 } else if (inputEl.createTextRange) {
  var range = inputEl.createTextRange();
  range.collapse(true);
  range.moveEnd('character', selEnd);
  range.moveStart('character', selStart);
  range.select();
 }
 inputEl.scrollTop += 40;
}

function scroll_1(){
	var ev = document.createEvent ('KeyEvents');
	ev.initKeyEvent('keypress', true, true, window,
	false, false, false, false, 0,
	element.value.charCodeAt(500-1));
	element.dispatchEvent(ev); // causes the scrolling
}



function elem(id) { return document.getElementById(id); }

function search(needle,haystack,start) {
var i, element = elem(haystack);
index = element.value.indexOf(needle,start||0);
if (index<0) {
window.status = "Not found: " + needle;
window.setTimeout (function(){window.status=''}, 4000); }
else {
element.setSelectionRange((i=index+needle.length)-1,i);
var ev = document.createEvent ('KeyEvents');
ev.initKeyEvent('keypress', true, true, window,
false, false, false, false, 0,
element.value.charCodeAt(i-1));
element.dispatchEvent(ev); // causes the scrolling
element.setSelectionRange(index, i);
}
}
</script>

<input type="button" value="bold" onclick="formatText ('b');" />
<input type="button" value="italic" onclick="formatText ('i');" />
<input type="button" value="underline" onclick="formatText ('u');" /><br/>
Set text size:
<input type="button" value="largest" onclick="setFontSize ('x-large');" />
<input type="button" value="larger" onclick="setFontSize ('large');" /><br/>
<input type="button" value="cursor" onclick="setSelRange(2000, 2000);" /><br/>
<input type="button" value="scroll_1" onclick="scroll_1();" /><br/>
<textarea name="myArea" id="myArea" cols="75" rows="15"></textarea>

